package set

import "fmt"

type Set struct {
	items map[any]any
}

var placeholder = struct{}{}

func New() Set {
	s := Set{}
	s.items = make(map[any]any)
	return s
}

func (s *Set) Put(value any) {
	s.items[value] = placeholder
}

func (s *Set) Contains(value any) bool {
	_, ok := s.items[value]
	return ok
}

func (s *Set) Empty() bool {
	for range s.items {
		return false
	}
	return true
}

func (s *Set) Len() int {
	return len(s.items)
}

func (s *Set) Delete(value any) {
	delete(s.items, value)
}

func (s *Set) Range(rangeFunc func(value any)) {
	for k := range s.items {
		rangeFunc(k)
	}
}

func (s *Set) ConvertToList() []any {
	var result []any
	for k := range s.items {
		result = append(result, k)
	}
	return result
}

func (s *Set) ToString() string {
	return fmt.Sprintf("%v", s.ConvertToList())
}
